package org.example.listener;

import lombok.extern.slf4j.Slf4j;
import org.example.service.SeckillService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class SeckillMessageListener {

    @Autowired
    private SeckillService seckillService;

    /**
     * 监听订单超时消息
     * @param orderId 订单ID
     */
    @RabbitListener(queues = "seckill.queue")
    public void handleOrderTimeoutMessage(Long orderId) {
        log.info("接收到订单超时消息，订单ID: {}", orderId);
        try {
            seckillService.handleOrderTimeout(orderId);
        } catch (Exception e) {
            log.error("处理订单超时消息失败，订单ID: {}", orderId, e);
        }
    }
}
